<?php

namespace IFI\Symfony2Bundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Article
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="IFI\Symfony2Bundle\Entity\ArticleRepository")
 */
class Article {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="titre", type="string", length=500)
     */
    private $titre;

    /**
     * @var string
     *
     * @ORM\Column(name="contenu", type="text")
     */
    private $contenu;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date", type="datetime")
     */
    private $date;

    /**
     * @ORM\ManyToOne(targetEntity="IFI\Symfony2Bundle\Entity\Auteur", inversedBy="articles")
     * @ORM\JoinColumn(nullable=false)
     */
    private $auteur;

    /**
     * @ORM\ManyToMany(targetEntity="IFI\Symfony2Bundle\Entity\Tag", cascade={"persist"})
     */
    private $tags;

    public function __construct() {
        $this->date = new \Datetime();
    }

    /**
     * Add tag
     *
     * @param \IFI\Symfony2Bundle\Entity\Tag $tag
     */
    public function addTag(\IFI\Symfony2Bundle\Entity\Tag $tag) { 
        $this->tags[] = $tag;
    }
    
    /**
     * Add tags
     *
     * @param array() $tag
     */
    public function addTags(array $tags = array()) { 
        foreach($tags as $tag) {
            if($tag instanceof \IFI\Symfony2Bundle\Entity\Tag)
                $this->tags[] = $tag;
        }
    }

    /**
     * Remove tag
     *
     * @param \IFI\Symfony2Bundle\Entity\Tag $tag
     */
    public function removeTag(\IFI\Symfony2Bundle\Entity\Tag $tag) { 
        $this->tags->removeElement($tag);
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Set titre
     *
     * @param string $titre
     * @return Article
     */
    public function setTitre($titre) {
        $this->titre = $titre;

        return $this;
    }

    /**
     * Get titre
     *
     * @return string 
     */
    public function getTitre() {
        return $this->titre;
    }

    /**
     * Set contenu
     *
     * @param string $contenu
     * @return Article
     */
    public function setContenu($contenu) {
        $this->contenu = $contenu;

        return $this;
    }

    /**
     * Get contenu
     *
     * @return string 
     */
    public function getContenu() {
        return $this->contenu;
    }

    /**
     * Set auteur
     *
     * @param \stdClass $auteur
     * @return Article
     */
    public function setAuteur($auteur) {
        $this->auteur = $auteur;

        return $this;
    }

    /**
     * Get auteur
     *
     * @return \stdClass 
     */
    public function getAuteur() {
        return $this->auteur;
    }

    /**
     * Set tags
     *
     * @param array $tags
     * @return Article
     */
    public function setTags($tags) {
        $this->tags = $tags;

        return $this;
    }

    /**
     * Get tags
     *
     * @return array 
     */
    public function getTags() {
        return $this->tags;
    }

    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Article
     */
    public function setDate($date) {
        $this->date = $date;

        return $this;
    }

    /**
     * Get date
     *
     * @return \DateTime 
     */
    public function getDate() {
        return $this->date;
    }

}
